home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
UTILITY
/
TASEXAM6.ARJ
/
PEAKS.TAS
< prev
next >
Wrap
Text File
|
1991-09-24
|
9KB
|
230 lines
{
* CAUTION YOU MUST HAVE THE SP-500 IN YOUR DATABASE FOR THE
INDEX TO WORK. ALSO YOU MAY NEED TO INCREASE YOUR SYMBOL
SIZE IN THE CONFIGURE SCREEN OF TAS.*
This script tries to determine cycle length by looking at the
average peaks and troughs of a zigzag indicator. The last five
peaks and troughs are averaged to try to determine the next
peak and trough. A second function of this script is to determine
trend strength by looking at a cycle average of price and volume.
The stocks are also compared to the SP-500 and then a percent
number is given to how over bought or over sold they are.
All indicators are based on the time period found in the zigzag
function. Cycle studies are usually given a 15% bandwidth so
keep this in mind. Also this looks at short cycles which may
be under the influence of longer cycles.
May 1991. Jerry Green
}
#max_quotes 120
#index 'SP-500'
#output_file 'Peaks.LST'
rs_trgr : number; { define some numbers }
so_trgr : number;
rt_trgr : number;
days_back : number;
rs_c : array; { define some arrays }
so_c : array;
rt_c : array;
rs_sort : array;
Z : ARRAY;
if first_ticker then
begin
writeln(' CYCLE, TREND AND VALUE STUDY BASED ON AVERAGE ZIGZAG CYCLES');
writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
writeln(' ');
toda = date; { get last day in first ticker}
end;
if quote_count <= 100 OR date <> toda then
goto skipticker; {skip short data file}
begin
pk_5 = 0; {make sure we are clear from}
tr_5 = 0; {one ticker to the next}
pk_4 = 0; {varibles to store peak and }
tr_4 = 0; {trough differences }
pk_3 = 0;
tr_3 = 0;
pk_2 = 0;
tr_2 = 0;
pk_1 = 0;
tr_1 = 0;
pks_t = 0; {peaks to troughs}
trs_p = 0; {troughs to peaks}
pks_ta = 0; {average of pks_t}
trs_pa = 0; {average of trs_p}
nx_pk = 0; {next peak}
nx_tr = 0; {next trough}
s_t = 0; {rate of change for ticker}
s_p = 0; {rate of change for index}
rel_str = 0; {relative strength to index}
ob_os = 0; {overbought oversold}
rs_trgr = 0; {relative strength accumulator}
so_trgr = 0; {stochastic accumulator}
rt_trgr = 0; {rate of change accumulator}
rs_sort = 0; {total of trgrs}
pt1 = 0; {varibles for storing peaks}
pt2 = 0;
pt3 = 0;
pt4 = 0;
pt5 = 0;
tp1 = 0; {varibles for storing troughs}
tp2 = 0;
tp3 = 0;
tp4 = 0;
tp5 = 0;
{-------------------ZIGZAG STUDY STARTS HERE-------------------}
if C >= 100 then {check close to determine %}
z_v = 2; {calculate a zigag ind }
if C <= 100 then
z_v = 5;
Z = ZIG(c,z_v,'%');
pt5 = peak(Z,5); {get peaks back 5 waves}
pt4 = peak(Z,4);
pt3 = peak(Z,3);
pt2 = peak(Z,2);
pt1 = peak(Z,1);
tp5 = trough(Z,5); {get troughs back 5 waves}
tp4 = trough(Z,4);
tp3 = trough(Z,3);
tp2 = trough(Z,2);
tp1 = trough(Z,1);
if pt1 >= 0 then {don't let a peak = 0}
pt1 = pt2;
if tp1 >= 0 then {don't let a trough = 0}
tp1 = tp2;
if pt5 < tp5 then {check out the waves dude}
goto backpeak {make sure you catch the first one}
else
goto backtrough;
:backpeak
pk_5 = pt5 - tp5;
tr_5 = tp5 - pt4; {now the cycle analysis starts}
pk_4 = pt4 - tp4; {we are finding the days from }
tr_4 = tp4 - pt3; {peak to trough, trough to peak}
pk_3 = pt3 - tp3; {the zigzag is used because it}
tr_3 = tp3 - pt2; {gives the best veiw of the past}
pk_2 = pt2 - tp2; {by looking ahead in the data }
tr_2 = tp2 - pt1; {this can tell us the cycles }
pk_1 = pt1 - tp1;
tr_1 = tp1;
goto cycle;
:backtrough
tr_5 = tp5 - pt5; {two models are used to take}
pk_5 = pt5 - tp4; {into account the difference }
tr_4 = tp4 - pt4; {in first peak or first trough}
pk_4 = pt4 - tp3;
tr_3 = tp3 - pt3;
pk_3 = pt3 - tp2;
tr_2 = tp2 - pt2;
pk_2 = pt2 - tp1;
tr_1 = tp1 - pt1;
pk_1 = pt1;
goto cycle;
:cycle
pks_t = pk_5+pk_4+pk_3+pk_2+pk_1; {add peaks to troughs}
trs_p = tr_5+tr_4+tr_3+tr_2+tr_1; {add troughs to peaks}
pks_ta = (0-(pks_t/5)); {determine peaks and change to +}
trs_pa = (0-(trs_p/5)); {do same for troughs }
nx_tr = pks_ta+pk_1; {peak and trough functions return negative}
nx_pk = trs_pa+tr_1; {numbers so we add last to avg to find next}
avg_c = (pks_ta + trs_pa)/2; {calculate and average cycle }
days_back = avg_c; {days to go back in rank section}
avg_c = int(avg_c);
{---------------ZIGZAG STOPS AND OB-OS STARTS------------------}
rs_c = rsi(avg_c); { calculate an RSI }
so_c = stoch(int(avg_c/2),3); { STOCHASTIC }
rt_c = roc(c,avg_c,'%'); { RATE OF CHANGE }
bb_top = bbandt(avg_c,2); { BOLLENGER TOP BAND }
bb_bot = bbandb(avg_c,2); { BOLLINGER BOTTOM BAND }
:loop1
if rs_c[days_back] > 70 then { a loop to accumulate counts for }
rs_trgr = rs_trgr + 1; { indicator performance }
if rs_c[days_back] < 30 then
rs_trgr = rs_trgr - 1;
if so_c[days_back] > 80 then
so_trgr = so_trgr + 1;
if so_c[days_back] < 20 then
so_trgr = so_trgr - 1;
if c > 100 then
n = 2 and nn = -2 { if ticker is > 100 change ROC }
else { to look at 2% change, if cheaper }
n = 7 and nn = -7; { use 7% a number William Oneil likes}
if rt_c[days_back] > n then
rt_trgr = rt_trgr + 1;
if rt_c[days_back] < nn then
rt_trgr = rt_trgr - 1;
days_back = days_back + 1; { increase counter by 1 until today }
if days_back >= 1 then { is reached. today is 0 }
goto done
else
goto loop1;
:done
rs_sort = rs_trgr + so_trgr + rt_trgr; { add them for final rank}
{------------OB-OS STOPS AND TREND STUDY STARTS HERE--------}
AVG_VOL = MOV(V,avg_c/2,'E'); {moving average of 1/2 cycle on volume}
IF V < AVG_VOL THEN {if todays vol is less than}
VS_TRGR = - 1; {the avgerage VS_TRGR =-1}
ELSE {if greater then VS_TRGR =1}
VS_TRGR = 1;
AVG_CLSE := MOV(C,avg_c,'E'); {use same logic for CS_TRGR}
IF C < AVG_CLSE THEN
CS_TRGR = -1;
ELSE
CS_TRGR = 1;
IF CS_TRGR = 1 AND VS_TRGR = 1 THEN {this is typical thinking of}
begin {how vol and price interact }
trend = 'STRONG UP -> HOLD LONG'; { refer to Jack}
su_trnd = su_trnd + 1; {Schwager's book A COMPLETE }
end; {GUIDE TO THE FUTURES MARKETS}
IF CS_TRGR = 1 AND VS_TRGR = -1 THEN {pages 367_371.}
begin
trend = 'WEAK UP -> SELL ???'; {we also keep track of the}
wu_trnd = wu_trnd + 1; {trends for a summary}
end;
IF CS_TRGR = -1 AND VS_TRGR = -1 THEN
begin
trend = 'STRONG DN -> HOLD SHORT';
sd_trnd = sd_trnd + 1;
end;
IF CS_TRGR = -1 AND VS_TRGR = 1 THEN
begin
trend = 'WEAK DN -> BUY ???';
wd_trnd = wd_trnd + 1;
end;
IF AVG_VOL = 0 THEN
trend = 'TICKER W/NO VOL';
{------------------TREND STUDY STOPS HERE------------}
writeln(ticker,' ','SHORT TERM TIMING AT',' ',avg_c,' ','day cycle',
' ',z_v,' ','% ZIGZAG');
writeln(' ','Average peak to trough',pks_ta,' ','days');
writeln(' ','Average trough to peak',trs_pa,' ','days');
writeln(' ','Next peak ',' ',nx_pk,' ','Last peak ',' ',pt1);
writeln(' ','Next trough',' ',nx_tr,' ','Last trough',' ',tp1);
writeln(' ','Close today',' ','Last peak',' ','Last trough');
writeln(' ',c,' ',c[pt1],' ',c[tp1]);
writeln(' ','Possible gain',' ',((c[pt1]-c)/c[pt1]),' ','%');
writeln(' ','Possible risk',' ',((c-c[tp1])/c),' ','%');
writeln(' ','Volume & price trend',' ',trend);
av_cyc = int(0 - avg_c);
s_p = ((index-index[av_cyc])/index[av_cyc])+1;
s_t = ((c-c[av_cyc])/c[av_cyc])+1;
rel_str = 50 + (100*((s_t/s_p)-1));
writeln(' ',avg_c,' ','Day Relative strength',' ',rs_c);
writeln(' ',int(avg_c/2),' ','Day Stochastic',' ',so_c);
writeln(' ',avg_c,' ','Day Rate of Change',' ',rt_c);
writeln(' ',avg_c,' ','Day Top Bollinger Band',' ',bb_top);
writeln(' ',avg_c,' ','Day Bottom Bollinger Band',' ',bb_bot);
writeln(' ','Relative strength to S&P. 50 is even',' ',rel_str);
if rs_sort = 0 then
writeln(' ','Ticker is evenly valued at this cycle!');
if rs_sort <> 0 then
ob_os = (rs_sort/avg_c)*100;
if rs_sort < 0 then
writeln(' ','Ticker is oversold by',' ',ob_os,' ','%');
if rs_sort > 0 then
writeln(' ','Ticker is overbought by',' ',ob_os,' ','%');
writeln('------------------------------------------------------------');
end;
:skipticker
if last_ticker then
end;